package com.bll;

import java.util.ArrayList;

import com.dal.OriginDAO;
import com.model.Origin;

public class OriginBLO {

	public enum OriginEnum {
		Coding(1), Syntax(2);

		private final int id;

		OriginEnum(int i) {
			id = i;
		}

		OriginEnum parse(int i) throws Exception {
			for (OriginEnum e : OriginEnum.values()) {
				if (e.id == id) {
					return e;
				}
			}
			return null;
		}
	}

	private int originId;
	private String originName;

	public OriginBLO(){
		
	}
	
	public OriginBLO(int originId, String originName) {
		super();
		this.originId = originId;
		this.originName = originName;
	}

	// Methods

	public static ArrayList<OriginBLO> loadAllOrigin() {
		ArrayList<Origin> list = new OriginDAO().select();
		return getOriginBLOListFromEntityList(list);
	}

	// Internal Methods
	private static ArrayList<OriginBLO> getOriginBLOListFromEntityList(
			ArrayList<Origin> list) {
		ArrayList<OriginBLO> originBLOlist = new ArrayList<OriginBLO>();
		for (Origin origin : list) {
			originBLOlist.add(getOriginBLOFromEntity(origin));
		}
		return originBLOlist;
	}

	private static OriginBLO getOriginBLOFromEntity(Origin entity) {
		return new OriginBLO(entity.getOriginID(), entity.getOriginName());
	}

	// Utility Methods
	public String getDisplayText() {
		return originName;
	}

	/**
	 * @return the originId
	 */
	public int getOriginId() {
		return originId;
	}

	/**
	 * @param originId
	 *            the originId to set
	 */
	public void setOriginId(int originId) {
		this.originId = originId;
	}

	/**
	 * @return the originName
	 */
	public String getOriginName() {
		return originName;
	}

	/**
	 * @param originName
	 *            the originName to set
	 */
	public void setOriginName(String originName) {
		this.originName = originName;
	}

}
